//
//  SYJSqlManager.swift
//  weibo
//
//  Created by 孙英建 on 16/4/28.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

// 数据库名称
private let myName = "status.db"

class SYJSqlManager {
    
    static let sharedTools: SYJSqlManager = SYJSqlManager()
    
    let queue: FMDatabaseQueue
    
    private init() {
        let path = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last! as NSString).stringByAppendingPathComponent(myName)
        
        queue = FMDatabaseQueue(path: path)
        
        creatTable()
    }
    
    // 创建表
    func creatTable(){
        let sql = "CREATE TABLE IF NOT EXISTS T_Status (" +
            "statusId integer PRIMARY KEY NOT NULL," +
            "status text," +
        "userId text) ;"
        
        queue.inDatabase { (db) -> Void in
            if db.executeStatements(sql) {
//                print("数据库创建成功")
            }else{
                print("数据库创建失败")
            }
        }
    }
    
    
}
